package cemp.util;


import java.util.HashMap;
import java.util.Map;

/**
 * 消息
 *
 * @author xushibai
 */
public class MessageUtils {

    public static String consTemplateMessage(String template,Map<String,Object> params ){
        String templateContent = template;
        for (String key : params.keySet()) {
            String reg = "${"+key+"}";
            templateContent = templateContent.replace(reg,params.get(key).toString());
        }
        return templateContent;
    }

    public static String consMiniMessage(String templateStr, Map<String,Object> params){
        for (String key : params.keySet()) {
            String reg = "\\{\\{" + key;
            templateStr = templateStr.replaceAll(reg,params.get(key).toString());
        }
        templateStr = templateStr.replaceAll(".DATA}}","");
        return templateStr;
    }

    public static HashMap<String,Object> miniFormParam(String value){
        HashMap<String,Object> data = new HashMap<>();
        data.put("value",value);
        return data;
    }

    public static HashMap<String,Object> transMiniParam(Map<String,Object> origin){
        HashMap<String,Object> rtnMap = new HashMap<>();
        for (String key : origin.keySet()) {
            rtnMap.put(key,MessageUtils.miniFormParam(origin.get(key).toString()));
        }
        return  rtnMap;
    }

}
